package com.pansky.crm.controller.business;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pansky.crm.annotation.OperateLog;
import com.pansky.crm.common.mybatisplus.ApiResult;
import com.pansky.crm.common.mybatisplus.ResultPageDto;
import com.pansky.crm.entity.Department;
import com.pansky.crm.entity.MessageManagement;
import com.pansky.crm.entity.Role;
import com.pansky.crm.entity.bo.page.MessageManagementBO;
import com.pansky.crm.service.MessageManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author ：guochi
 * @date ：Created in 2021/3/9 19:11
 * @description：消息管理controller
 */
@RestController
@RequestMapping("/messageManagement")
@OperateLog
@Api(tags = {"管理端-消息管理api"})
public class MessageManagementController {

    @Autowired
    private MessageManagementService messageManagementService;

    @ApiOperation(value = "分页查询消息列表",notes = "分页查询消息列表")
    @PostMapping("/page/query")
    public ApiResult<ResultPageDto> queryByPage(@RequestBody MessageManagementBO messageManagementBO) {
        return messageManagementService.queryByPage(messageManagementBO);
    }

    @ApiOperation(value = "更新消息管理", notes = "更新消息")
    @PostMapping("/update")
    public ApiResult<Boolean> updateMessageManagement(@RequestBody MessageManagement messageManagement) {
        return ApiResult.ok(messageManagementService.updateById(messageManagement));
    }

    @ApiOperation(value = "添加消息", notes = "添加消息")
    @PostMapping("/add")
    public ApiResult<Boolean> addMessageManagement(@Valid @RequestBody MessageManagement messageManagement) {
        return ApiResult.ok(messageManagementService.save(messageManagement));
    }

    @ApiOperation(value = "删除消息", notes = "删除消息")
    @GetMapping("/delete")
    public ApiResult<Boolean> delete(@RequestParam Integer id) {
        return ApiResult.ok(messageManagementService.removeById(id));
    }

    @ApiOperation(value = "获取所有启用消息", notes = "获取所有启用消息")
    @PostMapping("/getMsgList")
    public ApiResult<List<MessageManagement>> getMsgList() {
        QueryWrapper<MessageManagement> wrapper  = new QueryWrapper<>();
        wrapper.eq("is_disable",1);   //1：启用  0：禁用
        wrapper.orderByAsc("id");
        return ApiResult.ok(messageManagementService.list(wrapper));
    }

    @ApiOperation(value = "获取消息详情", notes = "获取消息详情")
    @GetMapping("/getMsgById")
    public ApiResult<MessageManagement> getMsgById(@RequestParam("id") Integer id) {
        return ApiResult.ok(messageManagementService.getById(id));
    }

}
